
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "config/NestConfig.h"
#include "NestConfigDialog.h"
#include "entity/NestPath.h"
#include "QListWidget"
#include "qgraphicsitem.h"
#include <QLabel>
#include <QHBoxLayout>
#include <chrono>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class Nest;
class MainWindow : public QMainWindow

{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    QGraphicsPathItem* NestPathToQGraphicsPathItem(NestPath& nestpath);
    void initPathsWindow();  // 初始化裁片窗
    void isEnableNest(); // 判断是否可以进行排料了

signals:
    void startGANest(); //遗传算法
    void startSANest(); //模拟退火

public slots:
    void importParts();
    void importBinPath();
    void saveSVGFile();
    void perpareNest();  // 打开nestconfig
    void openBinInfoDialog();
    void drawNestOutput(Individual& individual);
    void updateNestState(double uitilization, int out_count, double currentTemp);
    void stopNest();
    void cleanPathsWindow();
    void startNestThread(int algo_type);
    void deletePathItem(int id);

private:


    Ui::MainWindow *ui;
    QColor parts_color = QColor("#4d84ad");
    std::vector<NestPath> allPaths;
    NestPath bin;
    NestConfig *nestConfig;
    NestConfigDialog * nestConfigDialog;
    Nest *nest;
    QThread* myNestThread;
    QGraphicsScene *scene;
    QLabel* labelStatus;
    Individual bestIndividual;
    QHBoxLayout *partsViewLayout;
    int algorithm_type; // 1: GA , 2: SA
    int selected_size; // 被选中裁片数量
    std::chrono::high_resolution_clock::time_point start_time;
};

#endif // MAINWINDOW_H
